
import { _decorator, Component, Node, RigidBody, tween, Tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
import { GameMgr } from './GameMgr';



@ccclass('SpikeSky')
export class SpikeSky extends Component {
    // [1]
    // dummy = '';

    // [2]
    // @property
    // serializableDummy = 0;
    moveNode: Node = null;

    dir: number = 0;
    stopTime: number = 0;

    start() {
        this.moveNode = this.node.getChildByName("smashing_spikes_b");
        this.dir = 1;
        this.stopTime = 2;
    }

    update(deltaTime: number) {
        if (GameMgr.instance.isGameOver) return;

        this.stopTime += deltaTime;
        if (this.stopTime < 2) // 暂停时间
            return;

        let pos: Vec3 = this.moveNode.position;
        if (this.dir == 1 && pos.z >= 0.6) // 向上时转向
            this.dir = -1;
        else if (this.dir == -1 && pos.z <= 0)
            this.dir = 1;

        pos.z += 0.2 * deltaTime * this.dir;
        this.moveNode.position = pos;

    }
}


